﻿using System;
using System.Collections;
using System.Reflection;

namespace ConnectLib.DAO
{
    /// <summary>
    /// Status: 0 -> export success
    /// Status: 1 -> error import/export
    /// Status: 2 -> import: exist invoice id; export not exist invoice id
    /// Status: 3 -> status = 1 && status = 2
    /// </summary>
    public class ResQuickInvoice
    {
        public int Status { get; set; }
        public string ErrInv { get; set; }
        public string NotExistInv { get; set; }
    }

    public class InvoiceDao
    {
        private string _invId;
        private string _staffName;//nguoi nhap he thong -> staffcode
        private string _sender;
        private DateTime _startDate;
        private string _startPlace;
        private string _receiver;
        private DateTime _endDate;
        private string _endPlace;
        private string _customernote;
        private string _serviceName;
        private int _price;
        private string _postman;//nguoi giao/nhan hang -> staffcode
        private string _productName;
        private string _dimension;
        private float _weight;
		private string _productnote;
        private byte _release;

        public string InvId
        {
            set { _invId = value; }
            get { return _invId; }
        }

        public string StaffName
        {
            set { _staffName = value; }
            get { return _staffName; }
        }

        public string Sender
        {
            set { _sender = value; }
            get { return _sender; }
        }

        public DateTime StartDate
        {
            set { _startDate = value; }
            get { return _startDate; }
        }

        public string StartPlace
        {
            set { _startPlace = value; }
            get { return _startPlace; }
        }

        public string Receiver
        {
            set { _receiver = value; }
            get { return _receiver; }
        }

        public DateTime EndDate
        {
            set { _endDate = value; }
            get { return _endDate; }
        }

        public string EndPlace
        {
            set { _endPlace = value; }
            get { return _endPlace; }
        }

        public string CustomerNote
        {
            set { _customernote = value; }
            get { return _customernote; }
        }

        public string ServiceName
        {
            set { _serviceName = value; }
            get { return _serviceName; }
        }

        public int Price
        {
            set { _price = value; }
            get { return _price; }
        }

        public string Postman
        {
            set { _postman = value; }
            get { return _postman; }
        }

        public string ProductName
        {
            set { _productName = value; }
            get { return _productName; }
        }

        public string Dimension
        {
            set { _dimension = value; }
            get { return _dimension; }
        }

        public float Weight
        {
            set { _weight = value; }
            get { return _weight; }
        }
		
		public string ProductNote
        {
            set { _productnote = value; }
            get { return _productnote; }
        }

        public byte Release
        {
            set { _release = value; }
            get { return _release; }
        }

        public void InitEmptyValue()
        {
            _invId = string.Empty;
            _staffName = string.Empty;
            _sender = string.Empty;
            _startDate = DateTime.Now;
            _startPlace = string.Empty;
            _receiver = string.Empty;
            _endDate = DateTime.Now;
            _endPlace = string.Empty;
            _customernote = string.Empty;
            _serviceName = string.Empty;
            _price = 0;
            _postman = string.Empty;
            _productName = string.Empty;
            _dimension = string.Empty;
            _weight = .0f;
            _productnote = string.Empty;
            _release = 0;
        }

        public InvoiceDao()
        {
            InitEmptyValue();
        }

        public InvoiceDao(Hashtable hsObj)
        {
            InitEmptyValue();
            try
            {
                PropertyInfo[] arrProInfo = this.GetType().GetProperties();
                PropertyInfo proInfo;
                object objValue;
                string sValue;
                string proName;
                int i = 0;

                for (; i < arrProInfo.Length; i++)
                {
                    proInfo = arrProInfo[i];
                    proName = proInfo.Name.ToLower();
                    if (hsObj.ContainsKey(proName))
                    {
                        objValue = hsObj[proName];
                        if (proInfo.PropertyType.Name.ToLower() == "byte[]")
                        {
                            if (objValue != null && objValue != DBNull.Value)
                            {
                                proInfo.SetValue(this, (byte[]) objValue, null);
                            }
                        }
                        else
                        {
                            sValue = Convert.ToString(objValue);
                            if (string.IsNullOrEmpty(sValue))
                                continue;
                            switch (proInfo.PropertyType.Name.ToLower())
                            {
                                case "byte":
                                    proInfo.SetValue(this, Convert.ToByte(objValue), null);
                                    break;
                                case "int64":
                                    proInfo.SetValue(this, Convert.ToInt64(objValue), null);
                                    break;
                                case "int32":
                                    proInfo.SetValue(this, Convert.ToInt32(objValue), null);
                                    break;
                                case "datetime":
                                    proInfo.SetValue(this, Convert.ToDateTime(objValue), null);
                                    break;
                                case "byte[]":
                                    break;
                                case "single":
                                    proInfo.SetValue(this, Convert.ToSingle(objValue), null);
                                    break;
                                default:
                                    proInfo.SetValue(this, objValue, null);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
